function createProxy(value = 0) {
  return new Proxy(
    {},
    {
      get(_, key) {
        if (key === Symbol.toPrimitive) {
          return () => value;
        }
        return createProxy(value + Number(key));
      },
    }
  );
}

const add = createProxy();

console.log(add[1][2][3] + 4); // 10
console.log(add[5][2][3] + 4); // 14
